package com.ssy.lingxi.marketing.model.constant;

import com.ssy.lingxi.common.language.LanguageHolder;

import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;

/**
 * 平台活动内部状态
 * @author ds
 * @date 2021/6/18
 * @version 2.0.0
 */
public enum PlatformActivityInnerStatusEnum {

    ALL(0, "所有状态"),
    TO_BE_SUBMIT(1, "待提交"),
    SUBMITTED(2, "已提交"),
    TO_BE_EXAMINE_SIGN_UP(3, "待审核报名"),
    TO_BE_SUBMIT_EXAMINE(4, "待提交审核"),
    TO_BE_EXAMINE_1(5, "待审核(一级)"),
    EXAMINE_NO_PASS_1(6, "审核不通过(一级)"),
    TO_BE_EXAMINE_2(7, "待审核(二级)"),
    EXAMINE_NO_PASS_2(8, "审核不通过(二级)"),
    TO_BE_ONLINE(9, "待上线活动"),
    ONGOING(10, "已上线活动"),
    STOP(11, "活动终止"),
    END(12, "活动结束"),
    CANCEL(13, "活动取消"),
    ;

    private final Integer code;
    private final String message;

    PlatformActivityInnerStatusEnum(Integer code, String message) {
        this.code = code;
        this.message = message;
    }

    public Integer getCode() {
        return code;
    }

    public String getMessage() {
        return LanguageHolder.getName(this.getClass(), this.code);
    }

    public static String getMessage(Integer code) {
        PlatformActivityInnerStatusEnum statusEnum = Arrays.stream(PlatformActivityInnerStatusEnum.values()).filter(e -> e.getCode().equals(code)).findFirst().orElse(null);
        return statusEnum == null ? "" : statusEnum.getMessage();
    }

    /**
     * 是否可取消（3,4,5,6,7,8,9,11）
     */
    public static boolean canCancel(Integer code) {
        List<PlatformActivityInnerStatusEnum> collect = Stream.of(TO_BE_EXAMINE_SIGN_UP, TO_BE_SUBMIT_EXAMINE, EXAMINE_NO_PASS_1, EXAMINE_NO_PASS_1,
                TO_BE_EXAMINE_2, EXAMINE_NO_PASS_2, TO_BE_ONLINE, STOP).collect(Collectors.toList());
        return collect.stream().anyMatch(o -> o.getCode().equals(code));
    }

    /**
     * 是否可修改活动时间（3,4,6,8,11）
     */
    public static boolean canUpdateActivityTime(Integer code) {
        List<PlatformActivityInnerStatusEnum> collect = Stream.of(TO_BE_EXAMINE_SIGN_UP, TO_BE_SUBMIT_EXAMINE, EXAMINE_NO_PASS_1,
                EXAMINE_NO_PASS_2, STOP).collect(Collectors.toList());
        return collect.stream().anyMatch(o -> o.getCode().equals(code));
    }

    /**
     * 是否可修改报名时间（3）
     */
    public static boolean canUpdateSignUpTime(Integer code) {
       return TO_BE_EXAMINE_SIGN_UP.code.equals(code);
    }
}
